<?php
	/*ini_set("display_errors","1");
	error_reporting(E_ALL);*/
	require_once("../config.php");
	require_once("cClientePhone.php");
	
	$tipoMapas = array('mobile', 'satellite', 'terrain', 'hybrid');
	$tablaId = $_REQUEST['tablaId'];
	$objetivo = $_REQUEST['objetivo'];
	$aliasId = $_REQUEST['aliasId'];
	
	$objetivoDB = $_REQUEST['objetivoDB'];//objetivo del padre
	$cuentaFk 	= $_REQUEST['cuentaFk'];//cuenta del padre
	$filtro 	= $_REQUEST['filtro'];//cuenta del padre
	$movilId	= $_REQUEST['movilId'];//
	$aux = "";
	if($movilId!=""){
		$aux = $tablaId;
		$tablaId = $movilId;
	}
	if ($aliasId == NULL || trim($aliasId) == '') {
		$aliasId = $tablaId;
	}
	$datosCuenta = BykomClientePhone::Info_Alias_Phone($aliasId, $objetivo);
	//$gmapkey = $datosCuenta->campo('gmapkey',0);
	//$gmapkey = "ABQIAAAAb2cIl05JoEQ0tItv9ddwVBTYIvJQgRp2fkbTivtJ0-K9on5_qhQj9k1Tz7wiJYq_GK2nWiSYoKSn1w";
	$gmapkey = GMAP_KEY;
	$datosMovil = BykomClientePhone::Info_Movil($tablaId);
	$datosPosicionamiento = BykomClientePhone::Info_Posicion_Movil($tablaId);
	
   	if ($datosPosicionamiento->cantidad() < 1) {
   		exit("El movil no posee posicion actual.");
   	}
   	
   	$longitud = trim(BykomClientePhone::quitCero($datosPosicionamiento->campo('LONGITUD',0)));
	$latitud = trim(BykomClientePhone::quitCero($datosPosicionamiento->campo('LATITUD',0)));
	$zoom = $_REQUEST['zoom'];
	if (!isset($zoom)) {
		$zoom = $datosCuenta->campo('zoom',0);
		if ($zoom == NULL || trim($zoom) == '') {
			$zoom = 14;
		}
	}
	
	$maptype = $_REQUEST['maptype'];
	if (!isset($maptype)) {
		$maptype = $datosCuenta->campo('maptype',0);
		if ($maptype == NULL || trim($maptype) == '') {
			$maptype = "mobile";
		}
	}
	
	$width = 220;
	$height = 170;
	
	if (isset($_REQUEST['heigthDiv']) && $_REQUEST['heigthDiv'] != 0) {
		$height = $_REQUEST['heigthDiv'];
	}
	if (isset($_REQUEST['widthDiv']) && $_REQUEST['widthDiv'] != 0) {
		$width = $_REQUEST['widthDiv'];
	}
   	$URLMapa = "http://maps.google.com/staticmap?center=" .$latitud ."," . $longitud . 
						   "&zoom=" . $zoom . "&size=" . $width . "x" . $height . 
						   "&maptype=" . $maptype . "&key=" . $gmapkey . "&sensor=true&" .
						   "markers=" . $latitud ."," . $longitud .",blue&" .
						   "format=png";
							   
	
	//echo $URLMapa;					  
 ?>	

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Bykom Web Cliente</title>
	<link rel="stylesheet" href="css/phone.css" type="text/css" media="screen" charset="utf-8"/>
	<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
	<script type="text/javascript">

	  	var latitud 	= <?php echo $latitud;?>;
	  	var longitud	= <?php echo $longitud;?>;
		var zoom		= <?php echo $zoom;?>;
		var widthMap	= <?php echo $width;?>;
		var heightMap	= <?php echo $height;?>;
		
		function detectBrowser() {
		  var useragent = navigator.userAgent;
		  var mapdiv = document.getElementById("map_canvas");
		    
		  if (useragent.indexOf('iPhone') != -1 || useragent.indexOf('Android') != -1 ||  useragent.indexOf('Windows NT') != -1) {
		    mapdiv.style.width 	= '95%';
		    mapdiv.style.height = '95%';
		    document.getElementById("imgMapa").style.display = "none";
		    document.getElementById("tablaImg").style.display = "none";
		    document.getElementById("divMapa").style.display = "block";
		    document.getElementById("divMapa").style.width 	= widthMap+'px';
		    document.getElementById("divMapa").style.height = heightMap+'px';
		  } else {
		    mapdiv.style.width 	= widthMap+'px';
		    mapdiv.style.height = heightMap+'px';
		    document.getElementById("imgMapa").style.display = "block";
		    document.getElementById("tablaImg").style.display = "block";
		    document.getElementById("divMapa").style.display = "none";
		  }
		}
			
 	  function initialize() {
	    detectBrowser();  
	    var latlng = new google.maps.LatLng(latitud, longitud);
	    var myOptions = {
	      zoom: zoom,
	      center: latlng,
	      mapTypeId:  google.maps.MapTypeId.ROADMAP
	    };
	    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	    var marker = new google.maps.Marker({
	        position: latlng, 
	        map: map,
	        title:""
	    }); 
	  }
	
	</script>
	
</head>
<body  onload="initialize()">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle">
<div class="bodyContent">

<form name="filtroEventos" action="mapaCell2.php">
<input type="hidden" name="tablaId" id="tablaId" value="<?=$tablaId?>">
<input type="hidden" name="aliasId" id="aliasId" value="<?=$aliasId?>">
<input type="hidden" name="objetivo" id="objetivo" value="<?=$objetivo?>">
<input type="hidden" name="zoom" id="zoom" value="<?=$zoom?>">
<input type="hidden" name="maptype" id="maptype" value="<?=$maptype?>">

<?php
  	if($aux!=""){
   		$tablaId = $aux;
   	}
   	?>
<div class="top">	

	<table width="100%">
		<tr>
			<td class="labelTop">
				<span class="textTop"> <?= $datosMovil->campo('patente', 0);?>  </span>  
			</td>
            <td rowspan="2" width="105px" align="center" valign="middle">
            	<img src="images/WClogoTop.gif" border="0">
            </td>
		</tr>
		
	</table>
</div>
<div class="botonera">
	<table align="left">
		<tr>
			<td class="labelTop">
            	Mapeo
            </td>
		</tr>
	</table>
	
	<table align="right" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td align="right"> 
        		<a href="movilCell.php?filtro=<?=$filtro?>&movilId=<?=$movilId?>&tablaId=<?=$tablaId?>&objetivo=<?=$objetivo?>&aliasId=<?=$aliasId?>&objetivoDB=<?=$objetivoDB?>&cuentaFk=<?=$cuentaFk?>" title="Volver"><img src="images/BTNback.gif" border="0"/></a> 			
			</td>
			<td align="right"> 
        		<a href="welcomeCell.php" title="Salir/Logout"><img src="images/BTNexit.gif" border="0"/></a> 			
			</td>
		</tr>	
	</table>
</div>


<table id="tablaImg">
	<tr>
		<td class="label">
			Zoom: <select name="zoom" id="zoom">
			<? 
			for ($i = 1; $i < 19; $i++) {
				$selected = "";
				if ($zoom == $i) {
					$selected = "selected";
				}
				echo "<option value='" . $i . "' " . $selected . ">" . $i . "</option>";
			}
			?>
			</select>
		</td>
		<td class="label">
			Tipo: <select name="maptype" id="maptype">
			<? for ($i = 0; $i < count($tipoMapas); $i++) {
				$selected = "";
				if ($maptype == $tipoMapas[$i]) {
					$selected = "selected";
				}
				echo "<option value='" . $tipoMapas[$i] . "' " . $selected . ">" . $tipoMapas[$i] . "</option>";
			}
			?>
			</select>
		</td>
		<td>
        	<input type="submit" class="button" value="Refrescar"/>
        </td>                
	</tr>
	<tr>
		<td colspan="3" align="center">
			<img src="<?=$URLMapa?>" alt="mapa" border="1"  id="imgMapa" style="display:none;"/>
		</td>
	</tr>
</table>    
<div style="display:none;" id="divMapa" >
	<div id="map_canvas" ></div>
</div>
</form>
</div>
</td></tr></table>

</body>
</html>




